package com.example.garbage.pojo;

/**
 * @Author Shunrai
 * @create 2023/11/6 10:01
 * @Version 1.0
 * @Description
 */

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 公共返回对象
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "公共返回对象")
public class RespBean<T> {
    @Schema(description = "状态码")
    private long code;
    @Schema(description = "信息")
    private String message;
    @Schema(description = "是否成功")
    private boolean ok;
    @Schema(description = "数据")
    private T data;

    /**
     * 成功返回结果
     * @param message
     * @return
     */
    public static RespBean success(String message){
        return new RespBean(200,message,true,null);
    }

    /**
     * 成功返回结果
     * @param message
     * @return
     */
    public static<T> RespBean success(String message,T data){
        return new RespBean(200,message,true,data);
    }

    /**
     * 失败返回结果
     * @param message
     * @return
     */
    public static RespBean error(String message){
        return new RespBean(500,message,false,null);
    }

    /**
     * 失败返回结果
     * @param message
     * @return
     */
    public static<T> RespBean error(String message,T data){
        return new RespBean(500,message,false,data);
    }

}

